package com.edu.juc.completableFuture.completionStage;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class ExerTest {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return 1;
        }).thenCombine(CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return 2;
        }), Integer::sum).thenCombine(CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return 3;
        }), Integer::sum);

        System.out.println("main");
        System.out.println(future.join());
        long end = System.currentTimeMillis();
        System.out.println("耗时：" + (end - start));
    }
}
